package com.interactive1.dbutils;
import java.sql.*;

public class Sequence {
	public static final int nextval(String dbalias, String tablename) throws Exception {
		tablename = tablename.toUpperCase();
		int id;
		synchronized (tablename.intern()) {
			Connection con = ConnectionPool.getConnection(dbalias);
			Statement stmt = null;
			try {
				stmt = con.createStatement();
				ResultSet rs=stmt.executeQuery("select value from "+tablename);
				rs.next();
				id = rs.getInt(1);
				rs.close();
				stmt.executeUpdate("UPDATE "+tablename+" SET VALUE="+(id+1));
			} finally {
				if (stmt!=null) stmt.close();
				ConnectionPool.release(dbalias,con);
			}
			return id;
		}
	}
	public static final int nextval(String dbalias, String tablename, String dbType) throws Exception {
		if (dbType==null);
		return nextval(dbalias, tablename);
	}
}